package com.jfreer.mybatis.expand;

import com.jfreer.mybatis.expand.model.FreeworkBaseRecordGenerator;
import com.jfreer.mybatis.expand.model.FreeworkExampleGenerator;
import com.jfreer.mybatis.expand.model.FreeworkPrimaryKeyGenerator;
import com.jfreer.mybatis.expand.model.FreeworkRecordWithBLOBsGenerator;
import com.jfreer.mybatis.expand.xmlmapper.FreeworkXMLMapperGenerator;
import org.mybatis.generator.api.ProgressCallback;
import org.mybatis.generator.codegen.AbstractJavaClientGenerator;
import org.mybatis.generator.codegen.AbstractJavaGenerator;
import org.mybatis.generator.codegen.mybatis3.IntrospectedTableMyBatis3Impl;
import org.mybatis.generator.codegen.mybatis3.model.BaseRecordGenerator;
import org.mybatis.generator.codegen.mybatis3.model.ExampleGenerator;
import org.mybatis.generator.codegen.mybatis3.model.PrimaryKeyGenerator;
import org.mybatis.generator.codegen.mybatis3.model.RecordWithBLOBsGenerator;

import java.util.List;

/**
 * User: landy
 * Date: 14-6-23
 * Time: 上午8:51
 */
public class IntrospectedTableMyBatis3Freework extends IntrospectedTableMyBatis3Impl {
    @Override
    protected void calculateXmlMapperGenerator(AbstractJavaClientGenerator javaClientGenerator,
                                               List<String> warnings,
                                               ProgressCallback progressCallback) {
        xmlMapperGenerator = new FreeworkXMLMapperGenerator();

        initializeAbstractGenerator(xmlMapperGenerator, warnings,
                progressCallback);
    }

    protected void calculateJavaModelGenerators(List<String> warnings,
                                                ProgressCallback progressCallback) {
        if (getRules().generateExampleClass()) {
            AbstractJavaGenerator javaGenerator = new FreeworkExampleGenerator();
            initializeAbstractGenerator(javaGenerator, warnings,
                    progressCallback);
            javaModelGenerators.add(javaGenerator);
        }

        if (getRules().generatePrimaryKeyClass()) {
            AbstractJavaGenerator javaGenerator = new FreeworkPrimaryKeyGenerator();
            initializeAbstractGenerator(javaGenerator, warnings,
                    progressCallback);
            javaModelGenerators.add(javaGenerator);
        }

        if (getRules().generateBaseRecordClass()) {
            AbstractJavaGenerator javaGenerator = new FreeworkBaseRecordGenerator();
            initializeAbstractGenerator(javaGenerator, warnings,
                    progressCallback);
            javaModelGenerators.add(javaGenerator);
        }

        if (getRules().generateRecordWithBLOBsClass()) {
            AbstractJavaGenerator javaGenerator = new FreeworkRecordWithBLOBsGenerator();
            initializeAbstractGenerator(javaGenerator, warnings,
                    progressCallback);
            javaModelGenerators.add(javaGenerator);
        }
    }

    public String getDeleteAllStatementId() {
        return "deleteAll";
    }

    public String getCountAllStatementId() {
        return "countAll";
    }

    public String getCountBySelectiveStatementId() {
        return "countBySelective";
    }

    public String getDeleteBySelectiveStatementId() {
        return "deleteBySelective";
    }

    public String getSelectBySelectiveStatementId() {
        return "selectBySelective";
    }

    public String getDeleteInBatchStatementId() {
        return "deleteInBatch";
    }

    public String getInsertInBatchStatementId() {
        return "insertInBatch";
    }

    public String getUpdateByPrimaryKeySelectiveInBatchStatementId() {
        return "updateByPrimaryKeySelectiveInBatch";
    }
}
